﻿using System;

namespace Ndns.Packet.Abstractions.ResourceRecords
{
    public sealed class DnsResourceRecordSOA : DnsResourceRecord
    {
        public override DnsHostName HostName { get; set; }
        public override DnsRecordType Type { get => DnsRecordType.SOA; protected set => throw new NotSupportedException(); }
        public override DnsClass Class { get; protected set; }

        /// <summary>
        /// 表示应答中的CNAME记录。
        /// </summary>
        public DnsHostName PrimaryNameServer { get; set; }

        /// <summary>
        /// Responsible authority's mailbox.
        /// </summary>
        public DnsHostName MailBox { get; set; }

        public uint SerialNumber { get; set; }

        public uint RefreshInterval { get; set; }

        public uint RetrialInterval { get; set; }

        public uint ExpireLimit { get; set; }

        public uint MinimumTTL { get; set; }

        public DnsResourceRecordSOA(DnsHostName hostName, DnsClass c, uint ttl)
            : base(hostName, c, ttl)
        {
        }

        /// <summary>
        /// 根据相关信息构造DnsResourceRecordSOA实例。
        /// </summary>
        /// <param name="hostName">DNS应答的主机名信息。</param>
        /// <param name="c">DNS应答的类别。</param>
        /// <param name="ttl">DNS应答的超时时间。</param>
        public DnsResourceRecordSOA(DnsHostName hostName, DnsClass c, uint ttl,
            DnsHostName primaryNameAnswer, DnsHostName mailBox,
            uint serialNumber, uint refreshInterval, uint retrialInterval,
            uint expireLimit, uint minimumTTL)
            : base(hostName, c, ttl)
        {
            this.PrimaryNameServer = primaryNameAnswer;
            this.MailBox = mailBox;
            this.SerialNumber = serialNumber;
            this.RefreshInterval = refreshInterval;
            this.RetrialInterval = retrialInterval;
            this.ExpireLimit = expireLimit;
            this.MinimumTTL = minimumTTL;
        }

        public override DnsResourceRecord Clone()
        {
            return new DnsResourceRecordSOA(HostName, Class, TTL, PrimaryNameServer, MailBox, SerialNumber, RefreshInterval, RetrialInterval, ExpireLimit, MinimumTTL);
        }
        
    }
}
